package net.common.util;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;

public class FilePathUtils {

	public static String getFilePath(String path) {
		return ServletActionContext.getServletContext().getRealPath(path);
	}

	public static String getUploadFilePath() {
		return ServletActionContext.getServletContext().getRealPath("/upload/");
	}

	public synchronized static String createUploadFilePath(String type) {
		return ServletActionContext.getServletContext().getRealPath(
				"/upload/" + DateUtils.getCurrentDateToString(true) + type);
	}

	public static File createUploadFilePath(String type, File srcfile)
			throws IOException {
		File destfile = new File(createUploadFilePath(type));
		FileUtils.copyFile(srcfile, destfile);
		return destfile;
	}

	public static File getSheetXml() {
		String path = ServletActionContext.getServletContext().getRealPath("/template/htmlTemplate.xsl");
		return new File(path);
	}
	
	public static File getTemplateXml() {
		String path = ServletActionContext.getServletContext().getRealPath("/template/createquestionnaireTemplate.xsl");
		return new File(path);
	}
}